﻿using DZParallelLib.Test.Lib;
using System;
using System.IO;
using System.Linq;

namespace MakeLargeImageCollection
{
    class Program
    {
        /// <summary>
        /// Program to make a large image collection that can then be used to test the image maker.
        ///   usage: makelargeimagecollection n
        ///     n is an integer - number of images.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // Simple checking

            if (args.Length != 1)
            {
                Console.WriteLine("You need to specify an integer number that is the number of images to generate!");
                return;
            }

            int nImages = int.Parse(args[0]);
            Console.WriteLine("Generating {0} images.", nImages);

            //
            // Generate the basics
            //

            var imageBaseDir = new DirectoryInfo(Path.Combine(Path.GetTempPath(), "LargeImageDirectory"));
            if (imageBaseDir.Exists)
            {
                imageBaseDir.Delete(true);
            }
            imageBaseDir.Create();
            imageBaseDir.Refresh();

            var imageSCDir = new DirectoryInfo(Path.Combine(imageBaseDir.FullName, "sc"));
            imageSCDir.Create();

            //
            // We will just do the same image over and over.
            //

            var original = new FileInfo(@".\DZImage1\sc\vnpzyair.xml");
            if (!original.Exists)
            {
                Console.WriteLine("Unable to find source image file {0}. Fail!", original.FullName);
                return;
            }

            //
            // Now, do the copy
            //

            foreach (var item in Enumerable.Range(0, nImages))
            {
                GenerateImage(original, imageSCDir, item);
            }

        }

        /// <summary>
        /// Generate a single image.
        /// </summary>
        /// <param name="original"></param>
        /// <param name="imageSCDir"></param>
        /// <param name="item"></param>
        private static void GenerateImage(FileInfo original,DirectoryInfo imageSCDir,int item)
        {
            var newFilename = string.Format("{0}{1}.xml", Path.GetFileNameWithoutExtension(original.Name), item);
            original.GenerateNewDZFile(newFilename, imageSCDir);
        }

    }
}
